package com.dycx.message.converter;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.message.dto.MessageTaskDTO;
import com.dycx.message.entity.MessageTaskDO;
import com.dycx.message.vo.MessageTaskVO;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 模版任务表(MessageTask)实体转换类
 *
 * @author wuzongbin
 * @since 2023-11-14 09:23:58
 */


@Data
public class MessageTaskConverter implements Serializable {
    public static MessageTaskDO dtoToEntity(MessageTaskDTO dto) {
        if (dto == null) return null;
        MessageTaskDO entity = BeanUtil.toBean(dto, MessageTaskDO.class);
        return entity;
    }

    public static MessageTaskVO entityToVo(MessageTaskDO entity) {
        if (entity == null) return null;
        MessageTaskVO vo = BeanUtil.toBean(entity, MessageTaskVO.class);

        return vo;
    }

    public static List<MessageTaskVO> entityToVoList(List<MessageTaskDO> entityList) {
        List<MessageTaskVO> voList = new ArrayList<>();
        for (MessageTaskDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<MessageTaskVO> entityToVoPage(Page<MessageTaskDO> page) {

        List<MessageTaskVO> newRecords = new ArrayList<>();

        List<MessageTaskDO> records = page.getRecords();
        for (MessageTaskDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<MessageTaskVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
